package com.briup.mt.service.impl;

import com.briup.mt.bean.BaseFile;
import com.briup.mt.bean.BaseFileExample;
import com.briup.mt.bean.Counsel;
import com.briup.mt.dao.BaseFileMapper;
import com.briup.mt.service.IBaseFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;
@Service
public class BaseFileImpl implements IBaseFileService {


    @Autowired
    private BaseFileMapper baseFileMapper;

    @Override
    public List<BaseFile> qurey(String fileName) {
        BaseFileExample example = new BaseFileExample();
        if (!StringUtils.isEmpty(fileName)){
            example.createCriteria().andFileNameLike("%"+fileName+"%");
        }
        List<BaseFile> list = baseFileMapper.selectByExample(example);
        return list;
    }

    @Override
    public void saveOrUpdate(BaseFile baseFile) {
    if (baseFileMapper.selectByPrimaryKey(baseFile.getId()) == null){
        baseFileMapper.insert(baseFile);
    }else {
        baseFileMapper.updateByPrimaryKey(baseFile);
    }
    }

    @Override
    public void deleteById(String id) {
        baseFileMapper.deleteByPrimaryKey(id);
    }
}
